import type { ApiResponse, Model, Site } from '@/types/api'
import request from '@/utils/request'

// 站点管理API
export const siteApi = {
  // 获取站点树形结构
  getSiteTree(): Promise<ApiResponse<Site[]>> {
    return request({
      url: '/admin/site/tree',
      method: 'get'
    })
  },

  // 获取站点详情
  getSite(id: number): Promise<ApiResponse<Site>> {
    return request({
      url: `/admin/site/${id}`,
      method: 'get'
    })
  },

  // 创建站点
  createSite(data: Partial<Site>): Promise<ApiResponse<void>> {
    return request({
      url: '/admin/site',
      method: 'post',
      data
    })
  },

  // 更新站点
  updateSite(id: number, data: Partial<Site>): Promise<ApiResponse<void>> {
    return request({
      url: `/admin/site/${id}`,
      method: 'put',
      data
    })
  },

  // 删除站点
  deleteSite(id: number): Promise<ApiResponse<void>> {
    return request({
      url: `/admin/site/${id}`,
      method: 'delete'
    })
  },

  // 更新站点状态
  updateSiteStatus(id: number, status: number): Promise<ApiResponse<void>> {
    return request({
      url: `/admin/site/${id}/status`,
      method: 'put',
      params: { status }
    })
  },

  // 获取子站点
  getChildrenSites(parentId: number): Promise<ApiResponse<Site[]>> {
    return request({
      url: `/admin/site/${parentId}/children`,
      method: 'get'
    })
  },

  //获取站点栏目数据模型
  getSiteModels(siteId: number, type: number): Promise<ApiResponse<Model[]>> {
    return request({
      url: '/admin/model/site',
      method: 'get',
      params: { siteId, type }
    })
  }
}
